import { useState } from 'react';
import { PaginationResponse } from '@datorama/akita';

import { makeFacade, TwMessagesFacade } from '@/facade/messageEntityFacade';
import { PendingMessage } from '@/models/Message';
import { VISIBILITY_FILTER } from '@/models/commonType';
import { useObservable } from '@/utils/rxHelpers';

export type MsgsHookTuple = [TwMessagesFacade, PaginationResponse<PendingMessage>, VISIBILITY_FILTER];

//需要在页面用到的变量都在这里hook，主要用于简化页面调用逻辑和代码
export function useMsgsFacade(): MsgsHookTuple {
  const [msgsFacade] = useState(() => makeFacade());

  const [filter] = useObservable(msgsFacade.filter$, VISIBILITY_FILTER.SHOW_ALL);

  const [pagination] = useObservable(msgsFacade.pagination$, {} as PaginationResponse<PendingMessage>);

  return [msgsFacade, pagination, filter];
}
